import React, { memo } from 'react'
import { withRouter } from 'react-router-dom'
import { LogoutOutlined, HighlightOutlined } from '@ant-design/icons'

import eventBus from '@/utils/eventBus'
import { SettingWrapper } from '@/components/b_setting/style'

function B_Setting(props) {
  const { history } = props

  function handleMenuClick(e) {
    switch (e) {
      case '1':
        window.open('http://localhost:3023', '_blank')
        break
      case '2':
        eventBus.emit('exit')
        localStorage.removeItem('user')
        history.push('/login')
        break
      default:
        break
    }
  }

  return (
    <SettingWrapper>
      <ul>
        <li onClick={(e) => handleMenuClick('1')}>
          <span>
            <HighlightOutlined /> 管理后台
          </span>
        </li>
        <li onClick={(e) => handleMenuClick('2')}>
          <span>
            <LogoutOutlined /> 退出登录
          </span>
        </li>
      </ul>
    </SettingWrapper>
  )
}

export default memo(withRouter(B_Setting))
